/*************************************************************************
 * File Name   : mnt.c
 * Brief       :
 * Change Logs :
 * Date           Author       Notes
 * 2022\03\07     liqi         The first version.
*************************************************************************/

#include <rtthread.h>

#ifdef RT_USING_DFS
#include <dfs_fs.h>
#include "dfs_romfs.h"

int mnt_init(void)
{
    if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) == 0)
    {
        rt_kprintf("ROM file system initializated!\n");
    }
    else
    {
        rt_kprintf("ROM file system initializate failed!\n");
    }

    return 0;
}
INIT_ENV_EXPORT(mnt_init);

#include <stdio.h>
#include <dfs_posix.h>
int test_romfs(void)
{
    struct stat file_stat;
    int ret = RT_EOK;
    ret = stat("/mongoose/index.html", &file_stat);
    if(ret == 0)
    rt_kprintf("index.html file size = %d\n", file_stat.st_size);
    else
    rt_kprintf("index.html file not fonud\n");
    FILE *fp;
    fp = fopen("/mongoose/index.html", "rb");
    if (fp != NULL)
    {
        rt_kprintf("open index.html success\n");
        fclose(fp);
    }
    else
    {
        rt_kprintf("open index.html fail\n");
    }

    int fd;
    fd = open("/mongoose/index.html", O_RDONLY);
    if (fd > 0)
    {
        rt_kprintf("open index.html success\n");
        close(fd);
    }
    else
    {
        rt_kprintf("open index.html fail\n");
    }

}
MSH_CMD_EXPORT(test_romfs, test);
#endif
